package com.yikao.mini.demo.user;

import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import org.springframework.stereotype.Component;

import java.util.List;

@Component

@Mapper
public interface RxzYikaoMiniUserMapper {
    @Delete({
            "delete from rxz_yikao_mini_user",
            "where id = #{id,jdbcType=VARCHAR}"
    })
    int deleteByPrimaryKey(String id);

    @Insert({
            "insert into rxz_yikao_mini_user (id, mobile, ",
            "name)",
            "values (#{id,jdbcType=VARCHAR}, #{mobile,jdbcType=VARCHAR}, ",
            "#{name,jdbcType=VARCHAR})"
    })
    int insert(RxzYikaoMiniUser record);

    @Select({
            "select",
            "id, mobile, name",
            "from rxz_yikao_mini_user",
            "where id = #{id,jdbcType=VARCHAR}"
    })
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.VARCHAR, id = true),
            @Result(column = "mobile", property = "mobile", jdbcType = JdbcType.VARCHAR),
            @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR)
    })
    RxzYikaoMiniUser selectByPrimaryKey(String id);

    @Select({
            "select",
            "id, mobile, name",
            "from rxz_yikao_mini_user"
    })
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.VARCHAR, id = true),
            @Result(column = "mobile", property = "mobile", jdbcType = JdbcType.VARCHAR),
            @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR)
    })
    List<RxzYikaoMiniUser> selectAll();

    @Update({
            "update rxz_yikao_mini_user",
            "set mobile = #{mobile,jdbcType=VARCHAR},",
            "name = #{name,jdbcType=VARCHAR}",
            "where id = #{id,jdbcType=VARCHAR}"
    })
    int updateByPrimaryKey(RxzYikaoMiniUser record);


    //    自定义模糊查询：
    @Select({
            "select",
            "id, name, mobile",
            "from rxz_yikao_mini_user",
            "where name like '%${keyword}%' or mobile like '%${keyword}%' "
    })
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.VARCHAR, id = true),
            @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR),
            @Result(column = "mobile", property = "mobile", jdbcType = JdbcType.INTEGER)
    })
    List<RxzYikaoMiniUser> fuzzySelectU(@Param("keyword") String keyword);

}